﻿@using Newtouch.Infrastructure;
@{
    ViewBag.Title = "FoodForm";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style>
    .ui-jqgrid .ui-jqgrid-btable tbody tr.jqgrow td {
        border: 1px solid #ddd;
    }
    #gridssyzPager_center {
        display: none;
    }
    #linkssyz .ui-th-ltr, #linkssyz .ui-jqgrid .ui-jqgrid-htable th.ui-th-ltr {
        border: solid 1px #ddd;
    }
</style>
<link href="@SiteUrl.GetStaticResourceScriptUrl("~/Content/css/cispage.css", false)" rel="stylesheet" />
<script src="@SiteUrl.GetStaticResourceScriptUrl("~/js/validate/jquery.validate.min.js")"></script>
<link href="@SiteUrl.GetStaticResourceScriptUrl("~/Content/css/wmgridmenu.css", false)" rel="stylesheet" />
<div id="linkssyz" style="width:100%;">
    <table id="gridssyz"></table>
    <table id="gridssyzPager"></table>
    <form id="form1">
        <table class="form" style="margin-top:10px;">
            <tr>
                <th class="formTitle"><span class="required">*</span>模板名称: </th>
                <td class="formValue">
                    <input id="mbmc" name="mbmc" type="text" class="form-control required" />
                </td>
                <td class="formValue">
                    <input type="button" id="" class="btn btn-primary" value="保存" style="margin-left:20%; width:20%;" onclick="SaveSS()" />
                    <input type="button" id="" class="btn btn-primary" value="删除" style="margin-left:10%; width:20%;" onclick="Delete()" />
                </td>
                <td colspan="2"></td>
            </tr>
        </table>
    </form>
</div>

<script>
    var mbId = $.request("mbId");
    var localdata = [];
    var deldata = [];//删除对象
    $(function () {
        gridssyz();
		    if (mbId) {
            $.najax({
                url: "/DoctorManage/DoctorsAdvice/GetMBDetailByMainId",
                dataType: "json",
                data: { Id: mbId },
                type: "POST",
                success: function (localdata) {
                    if (localdata !== typeof (undefined) && localdata.length > 0) {
                        $.each(localdata, function () {
                            this.action = getSSActionStr();
                            this.ssxh = this.xmdm;
                            this.ssxhdm = this.xmdm;
                            this.ssxhval = this.xmmc;
                        });
                        $("#gridssyz").jqGrid('setGridParam', {
                            datatype: 'local',
                            data: localdata
                        }).trigger("reloadGrid");

                        $('#mbmc').val(localdata[0].tcmc);
                    }
                }
            });
        }
    });

    //列表
    function gridssyz() {
        var $gridssyz = $("#gridssyz");
        $gridssyz.jqGrid({
            datatype: 'local',
            data: localdata,
            height: $(window).height() - 200,
            shrinkToFit: true,   //true:按比例初始化列宽度 false:使用colModel指定的宽度
            autowidth: true,
            rownumbers: true,  //是否显示序号
            editurl: "clientArray",  //行编辑不向服务器提交数据
            unwritten: false,
            colModel: [
                { label: 'Id', name: 'Id', align: 'center', hidden: true },
                { name: 'DietBigType', hidden: true, editable: true },//大分类
                {
                    label: '<span class="required">*</span>膳食型号', name: 'ssxh', width: 100, editwidth: '80%', align: 'center', edittype: "select", editable: true, editoptions: {
                        dataEvents: [
                            {
                                type: 'change',
                                fn: function (e) {
                                    var row = $(e.target).closest('tr.jqgrow');
                                    var rowid = row.attr('id');
                                    $("#" + rowid + "_ssxhdm").val($(this).val());
                                    $("#" + rowid + "_ssxhval").val($(this).find("option:selected").text());
                                    var dfl = $(this).find("option:selected").attr('data-DietBigType');
                                    if (dfl != undefined && dfl != "") {
                                        inityszsFloat(rowid, dfl);
                                    }
                                    generateysinfo(rowid, $(this).val());//生成膳食类别和膳食指示,禁用文本框
                                }
                            }
                        ]

                    }, editrules: { required: true }
                },
                { label: 'ssxhdm', name: 'ssxhdm', hidden: true, editable: true, editrules: { required: true } },
                { label: 'ssxhval', name: 'ssxhval', hidden: true, editable: true, editrules: { required: true } },
                {
                    label: '膳食类别', name: 'yslb', name: 'yslb', width: 100, editwidth: '70%', align: 'center', editable: true, edittype: "select", editoptions: {
                        dataEvents: [
                            {
                                type: 'change',
                                fn: function (e) {
                                    var row = $(e.target).closest('tr.jqgrow');
                                    var rowid = row.attr('id');
                                    $("#" + rowid + "_yslbdm").val($(this).val());
                                    if ($(this).find("option:selected").text() == "膳食自备") {
                                        $("#" + rowid + "_yszs").val('').attr('disabled', 'true').css('background-color', '#f6f7fb');//禁用饮食指示
                                    } else {
                                        $("#" + rowid + "_yszs").removeAttr('disabled').css('background-color', 'white');//禁用饮食指示
                                    }
                                }
                            }
                        ]

                    }
                }, {
                    name: 'yslbdm', width: 100, editwidth: '100%', hidden: true, editable: true
                },
                {
                    label: '膳食指示', name: 'yszs', width: 100, editwidth: '100%', align: 'center', editable: true
                },
                {
                    name: 'yszsval', width: 100, editwidth: '100%', hidden: true, editable: true
                },
                {
                    label: '剂量', name: 'ypjl', width: 55, editwidth: '100%', align: 'center', editable: true, editoptions: {
                        dataEvents: [
                            {
                                type: 'change',
                                fn: function (e) {
                                    var cellval = $(this).val();
                                    var row = $(e.target).closest('tr.jqgrow');
                                    var rowid = row.attr('id');
                                    var dfl = $("#" + rowid + "_DietBigType").val();
                                    if (dfl == "YYBCJ" && cellval.replace(/(^\s*)|(\s*$)/g, "") == "") {
                                        $.modalAlert("剂量为空，请确认。", 'warning');
                                        return;
                                    }
                                    if (isNaN(cellval)) {
                                        $.modalAlert("剂量：请填写数字", 'warning');
                                        $(this).val('')
                                        return;
                                    }
                                }
                            }
                        ]
                    }
                },
                { label: '<span class="required">*</span>频次', name: 'pcmc', width: 60, editwidth: '100%', align: 'center', editrules: { required: true }, editable: true },
                { label: 'pcCode', name: 'pcCode', editwidth: '100%', align: 'center', editable: true, hidden: true },
                {
                    label: '能量密度', name: 'nlmd', width: 100, editwidth: '80%', align: 'center', edittype: "select", editable: true, editoptions: {
                        dataEvents: [
                            {
                                type: 'change',
                                fn: function (e) {
                                    var row = $(e.target).closest('tr.jqgrow');
                                    var rowid = row.attr('id');
                                    $("#" + rowid + "_nlmddm").val($(this).val());
                                }
                            }
                        ]

                    }
                },
                { label: 'nlmddm', name: 'nlmddm', editwidth: '100%', align: 'center', editable: true, hidden: true },
                { label: 'yfmcval', name: 'yfmcval', width: 75, editwidth: '100%', align: 'center', editable: true, hidden: true },
                {
                    label: '<span class="required">*</span>用法', name: 'yfmc', width: 100, editwidth: '70%', align: 'center', edittype: "select", editable: true, editoptions: {
                        dataEvents: [
                            {
                                type: 'change',
                                fn: function (e) {
                                    var row = $(e.target).closest('tr.jqgrow');
                                    var rowid = row.attr('id');
                                    $("#" + rowid + "_ypyfdm").val($(this).val());
                                    $("#" + rowid + "_yfmcval").val($(this).find("option:selected").text());
                                }
                            }
                        ]

                    }, editrules: { required: true }
                },
                { label: 'ypyfdm', name: 'ypyfdm', width: 75, editwidth: '100%', align: 'center', editable: true, hidden: true },
                { label: 'zxcs', name: 'zxcs', editable: true, hidden: true },
                { label: 'zxzq', name: 'zxzq', editable: true, hidden: true },
                { label: 'zxzqdw', name: 'zxzqdw', editable: true, hidden: true },
                { label: '嘱托', name: 'ztnr', width: 140, editwidth: '100%', align: 'center', editable: true },
                { label: '操作', name: 'action', width: 80, align: 'center' },
                { name: 'ysgh', hidden: true },
                { name: 'yzlx', hidden: true }
            ],
            editinputwidthborder: false,    //是否需要边框 默认为true
            editinputborderradius: false,   //是否需要边框圆角 默认true（有圆角）
            pager: "gridssyzPager",
            loadComplete: function () {
                if (localdata && localdata.length == 0) {
                    newPresData();
                }
            },
            gridComplete: function () {
                EnableInlineEditBox();
                //隐藏grid底部滚动条
                $gridssyz.closest(".ui-jqgrid-bdiv").css({ "overflow-x": "hidden" });
            }
        });

        //二级菜单
        $gridssyz.jqGrid('setGroupHeaders', {
            useColSpanStyle: true,
            groupHeaders: [
                {
                    startColumnName: 'ssxh',
                    numberOfColumns: 6,
                    titleText: '膳食信息'
                }]
        });

        //自定义按钮
        $gridssyz.navGrid('#gridssyzPager',
            { edit: false, add: false, del: false, search: false, refresh: false, view: false, position: "left", cloneToTop: false })
            .navButtonAdd('#gridssyzPager',
            {
                buttonicon: "glyphicon glyphicon-new-window",
                title: "新明细",
                caption: "新明细",
                position: "first",
                onClickButton: function () {
                    newPresData();
                },
            })
    }

    function inityszsFloat(rowid, dfl) {
        $('body').find('div#divfloat_' + $("#" + rowid + "_yszs").attr('id')).remove();
        $("#" + rowid + "_yszs").yszsFloatingSelector({
            showtext: 'Name',
            attrcols: ['Id', 'Name', 'DietGroup'],
            searchdl: dfl,
            mutiselect: dfl == "PTSS",
            checkItemActivity: function ($li, $thisinput) {
                var selected = false;//默认没有选中当前值
                var selectval = $thisinput.val();
                if (selectval) {
                    selectval = selectval.split(',');
                    $.each(selectval, function () {
                        if (this == $li.html()) {
                            selected = true;
                        }
                    });
                }
                return selected;
            },
            itemdbclickhandler: function ($this) {
                var mcval = "";
                var ssIds = "";
                if (typeof ($this) !== "undefined") {
                    $.each($this, function () {
                        if (dfl == "PTSS") {
                            mcval += this.attr('data-Name') + ",";
                            ssIds += this.attr('data-Id') + ",";
                        } else {
                            mcval += $(this).attr('data-Name') + ",";
                            ssIds += $(this).attr('data-Id') + ",";
                        }
                    });
                    if (mcval.length > 0) {
                        mcval = mcval.substring(0, mcval.length - 1);
                    };
                }
                $("#" + rowid + "_yszs").val(mcval);
                $("#" + rowid + "_yszsval").val(ssIds);

            },
        });
    }

    //启用行内编辑
    function EnableInlineEditBox() {
        var ids = $("#gridssyz").getDataIDs();
        $.each(ids, function () {
            var rowid = String(this);
            //打开编辑模式
            $("#gridssyz").jqGrid('editRow', rowid, false, initInlineFunc);
        });
    }

    //初始化 浮层
    function initInlineFunc(rowid) {
        var currentssxh=  $("#" + rowid + "_ssxhdm").val();
        $.najax({
            url: "/NurseManage/DietaryAdvice/GetSSXH",
            data: {from:"kyz"},
            dataType: "json",
            type: "POST",
            success: function (data) {
                var ysxhoption = "<option>请选择</option>";
                if (data != undefined && data.length > 0) {
                    $.each(data, function (idx, val) {
                        if (currentssxh === val.Id) {
                            ysxhoption += "<option value=" + val.Id + " data-DietBigType=" + val.DietBigType + " selected>" + val.Name + "</option>";
                        } else {
                            ysxhoption += "<option value=" + val.Id + " data-DietBigType=" + val.DietBigType + ">" + val.Name + "</option>";
                        }
                    });
                    $("#" + rowid + "_DietBigType").parent().next().children('select').append(ysxhoption);
                    $("#" + rowid + "_DietBigType").parent().next().children('select').trigger("change");
                    generateysinfo(rowid, currentssxh);
                }
            }
        });
        $("#" + rowid + "_ssxhval").parent().next().children('select').html('');
        Generatessypyfoption(rowid);
        Generatenlmdoption(rowid);
        var currlineId = $("#gridssyz").getRowData(rowid).Id;
        $("#" + rowid + "_pcmc").attr('readonly','true');
        //频次浮层
        $("#" + rowid + "_pcmc").pcFloatingSelector({
            showtext: 'yzpcmc',
            attrcols: ['yzpcmc', 'yzpcCode', 'zxcs', 'zxzq', 'zxzqdw'],
            itemdbclickhandler: function ($this) {
                $("#" + rowid + "_pcmc").val($this.attr('data-yzpcmc'));
                $("#" + rowid + "_pcCode").val($this.attr('data-yzpcCode'));
                $("#" + rowid + "_zxcs").val($this.attr('data-zxcs'))
                $("#" + rowid + "_zxzq").val($this.attr('data-zxzq'))
                $("#" + rowid + "_zxzqdw").val($this.attr('data-zxzqdw'));

                var pcCode = $("#" + rowid + "_pcCode").val();
                //临时医嘱天数禁用
                if ('@ViewBag.pcStr' !== '' && pcCode !== '' && (!isNaN(pcCode)) &&
                    (('@ViewBag.pcStr').indexOf(pcCode) > -1)) {
                    $("#" + rowid + "_ts").css('background-color', '#f6f7fb').attr('readonly', 'true');
                } else {
                    $("#" + rowid + "_ts").css('background-color', 'white').removeAttr('readonly');
                }
            },
        });

        //嘱托浮层
        $("#" + rowid + "_ztnr").ztFloatingSelector({
            height: 100,
            itemdbclickhandler: function ($this) {
                $("#" + rowid + "_ztnr").val($this.attr('data-ztmc'));
            },
        });
    }

    //新增 按钮
    function newPresData() {
        var dataRow = {
             Id: Math.random().toString() + new Date().getMilliseconds(),
                action: getSSActionStr(),
                yzlx: @Html.Raw(((int)EnumYzlx.ssyz).ToString())
        };
        $("#gridssyz").jqGrid("addRowData", undefined, dataRow, "first");
    }

    //删除明细
    function deleteRowData(selRowId, recalc) {
        if (!!selRowId) {
           var Id= $("#gridssyz").jqGrid('getRowData', selRowId).Id;
            $("#gridssyz").jqGrid("delRowData", selRowId);
            if (Id.indexOf("0.")=='-1') {//记录下来，从数据库删除
                deldata.push(Id);
            }
        }
    }

    function getSSActionStr() {
        return "<input class='btn btn-default btn-md btn_del' type='button' value='Delete' onclick='deleteRowData($(this).parent().parent().attr(\"id\"))'/>";
      }

      //保存
    function SaveSS() {
        //if (Validatessyz()) {//验证数据
        var mbmc = $('#mbmc').val();
        if (mbmc == "" && isNaN(mbmc)) {
            $.modalAlert("缺少模板名称", "warning");
            return false;
        }
            //获取所有行Id，遍历使编辑框处于保存状态
            var rowIds = $("#gridssyz").jqGrid('getDataIDs');
            var validationFailedArr = [];
            for (var i = 0; i < rowIds.length; i++) {
                var saveResult = $("#gridssyz").saveRow(rowIds[i], null, null, null, function (callbackRowId) { }, null, null);
                var rowData = $("#gridssyz").jqGrid('getRowData', rowIds[i]);
                if (!Validatessyz(rowData)) {
                    validationFailedArr.push(rowIds[i]);
                }
            }
            if (validationFailedArr != null && validationFailedArr.length > 0) {
                for (var i = 0; i < validationFailedArr.length; i++) {
                    $("#gridssyz").jqGrid('editRow', validationFailedArr[i], false, initInlineFunc);//打开编辑模式
                }
                return;
            }

            var gridssyzData = $("#gridssyz").jqGrid('getRowData_AllLine', null, true);
            if (gridssyzData.length < 1) {
                $.modalAlert("当前没有保存的套餐内容", 'warning');
            }
            $.each(gridssyzData, function () {    //去掉action
                for (var i = 0; i < $(this).length; i++) {
                     delete $(this)[i].action;
                     $(this)[i].ysgh = '@ViewBag.ysgh';
                     $(this)[i].xmdm = $(this)[i].ssxhdm;
                     $(this)[i].xmmc = $(this)[i].ssxh;
                }
            });
            submitService(gridssyzData);

        //}
    }

    //提交到后台
    function submitService(gridssyzData) {
        //套餐表
        var mbObj = {
            Id: mbId,
            tcfw: $.currentWindow().$('#current').attr('data-type'),
            tclx: @Html.Raw(((int)EnumYzlx.ssyz).ToString()),
            tcmc: $('#mbmc').val()
        }
        $.najax({
            url: "@Url.Action("Submit")",
            dataType: "json",
            data: { mbObj: mbObj, mbDetailList: gridssyzData },
            type: "POST",
            loadingtext: "套餐数据保存中，请稍后...",
            success: function (data) {
                $.modalMsg("保存成功", 'success');
                   if(!mbId && data.data){
                    mbId = data.data;
                    $.currentWindow().expandyzlx = @Html.Raw(((int)EnumYzlx.ssyz).ToString());
                    $.currentWindow().$("#beveltabs a[id='current']").trigger('click');
                }
                location.href = "/TemplateManage/DoctorServiceTemplate/FoodForm?mbId=" + mbId;
            }
        });
    }

    //验证
    function Validatessyz(rowdata) {
        //是否有数据
        //var data = $("#gridssyz").jqGrid('getRowData_AllLine', null, true);
        //if (data.length==0) {
        //    $.modalAlert("缺少套餐数据", 'warning');
        //    return false;
        //}
        var ssxh = rowdata.ssxhval;//$("#" + rowid + "_ssxhval").val();
        var yslb = rowdata.yslbdm;//$("#" + rowid + "_yslbdm").val();
        var yszs = rowdata.yszs;//$("#" + rowid + "_yszs").val();
        var dbt = rowdata.DietBigType;//$("#" + rowid + "_DietBigType").val();
        var ypyfdm = rowdata.ypyfdm;//$("#" + rowid + "_ypyfdm").val();
        var nlmddm = rowdata.nlmddm;//$("#" + rowid + "_nlmddm").val();
        var ypjl = rowdata.ypjl;
        if (ssxh == "") {
            $.modalAlert("缺少膳食型号", "warning");
            return false;
        }
        if (dbt == 'PTSS' && ssxh != '禁食' && yslb == '') {
            $.modalAlert("缺少膳食类别", "warning");
            return false;
        }
        if ((dbt == 'CNYY' || dbt == 'YYBCJ') && yszs == '') {
            $.modalAlert("缺少膳食指示", "warning");
            return false;
        }
        if (dbt == "YYBCJ" && ypjl.replace(/(^\s*)|(\s*$)/g, "") == "") {
            $.modalAlert("缺少剂量", 'warning');
            return;
        }
        if (rowdata.pcCode == "") {
            $.modalAlert("缺少频次", "warning");
            return false;
        }

        if (dbt == 'CNYY' && nlmddm == '') {
            $.modalAlert("缺少能量密度", "warning");
            return false;
        }
        if (ypyfdm == '') {
            $.modalAlert("缺少膳食用法", "warning");
            return false;
        }
        return true;
       
    }

    function Delete() {
        if (mbId == null || mbId == "") {
            $.modalAlert("缺少套餐", "warning");
            return;
        }
            $.najax({
            url: "@Url.Action("Delete")",
            dataType: "json",
            data: { mbId: mbId},
            type: "POST",
            loadingtext: "套餐数据删除中，请稍后...",
            success: function (data) {
                $.modalMsg("删除成功", 'success');
                $.currentWindow().$("#beveltabs a[id='current']").trigger('click');
                location.href = "/TemplateManage/DoctorServiceTemplate/FoodForm?mbId=";
            }
        });
    }

    //生成膳食类别
    function generateysinfo(rowid, $thisval) {
        var currentyslb = $("#" + rowid + "_yslbdm").val();
        if (currentyslb !== "") {
            $("#" + rowid + "_ssxhval").parent().next().children('select').removeAttr('disabled').css('background-color', 'white').html('');
        }
        if ($thisval !== "") {
            $.najax({
                url: "/NurseManage/DietaryAdvice/GetYSLB",
                data: { Id: $thisval },
                dataType: "json",
                type: "POST",
                success: function (data) {
                    $("#" + rowid + "_ssxhval").parent().next().children('select').html('');
                    //$("#" + rowid + "_yslbdm").val('');//清空膳食类别
                    var yslboption = "<option>请选择</option>";
                    if (data != undefined && data.length > 0) {
                        $.each(data, function (idx, val) {
                            if (currentyslb == val.Id) {
                                yslboption += "<option value=" + val.Id + " selected>" + val.Name + "</option>";
                            } else {
                                yslboption += "<option value=" + val.Id + ">" + val.Name + "</option>";
                            }
                        });
                        $("#" + rowid + "_ssxhval").parent().next().children('select').append(yslboption);
                    } else {
                        $("#" + rowid + "_ssxhval").parent().next().children('select').html('').attr("disabled", 'true').css('background-color', '#f6f7fb');
                    }
                }
            });
        }
        var dfl = $("#" + rowid + "_DietBigType").parent().next().children('select').find("option:selected").attr('data-DietBigType');
        var lastdfl = $("#" + rowid + "_DietBigType").val();
        $("#" + rowid + "_DietBigType").val(dfl);
        if (lastdfl !== "" && lastdfl !== dfl) {//修改大分类，清空膳食指示
            $("#" + rowid + "_yszs").val('');
            $("#" + rowid + "_yszsval").val('');
        }
        if (dfl == "PTSS") {//普通膳食 频次QD，剂量，能量密度禁用
            var ssxh = $("#" + rowid + "_ssxhval").val();
            if (ssxh == "禁食") {
                $("#" + rowid + "_yszs").attr('disabled', 'true').css('background-color', '#f6f7fb');//禁用膳食指示
                $("#" + rowid + "_yszs").val('');
                $("#" + rowid + "_yszsval").val('');
            } else {
                $("#" + rowid + "_ssxhval").parent().next().children('select').removeAttr('disabled').css('background-color', 'white');
                $("#" + rowid + "_yslbdm").parent().next().children('select').removeAttr('disabled').css('background-color', 'white');
            }
            $("#" + rowid + "_pcmc").attr('disabled', 'true').css('background-color', '#f6f7fb');
            $("#" + rowid + "_pcmc").val('QD');
            $("#" + rowid + "_pcCode").val('05');
            $("#" + rowid + "_zxcs").val('3')
            $("#" + rowid + "_zxzq").val('1')
            $("#" + rowid + "_zxzqdw").val('0');
            $("#" + rowid + "_ypjl").attr('disabled', 'true').css('background-color', '#f6f7fb');//禁用频次
            $("#" + rowid + "_pcCode").parent().next().children('select').html('').attr('disabled', 'true').css('background-color', '#f6f7fb');//禁用能量密度
        } else if (dfl == "CNYY") { //肠内营养 频次默认ST，可用，剂量500ml
            $("#" + rowid + "_ypjl").val('500').attr('disabled', 'true').css('background-color', '#f6f7fb');
            $("#" + rowid + "_pcCode").parent().next().children('select').removeAttr('disabled').css('background-color', 'white');//解禁能量密度
            $("#" + rowid + "_ypjl").removeAttr('disabled').css('background-color', 'white');//解禁频次
            Generatenlmdoption(rowid);//生成能量密度下拉框
            $("#" + rowid + "_yszs").removeAttr('disabled').css('background-color', 'white');//解禁膳食指示
        } else if (dfl == "YYBCJ") { //营养补充剂 频次默认ST，禁用，用法默认口服，禁用，天数禁用
            $("#" + rowid + "_pcmc").attr('disabled', 'true').css('background-color', '#f6f7fb');
            $("#" + rowid + "_pcmc").val('ST');
            $("#" + rowid + "_pcCode").val('00');
            $("#" + rowid + "_zxcs").val('1')
            $("#" + rowid + "_zxzq").val('1')
            $("#" + rowid + "_zxzqdw").val('1');
            $("#" + rowid + "_yfmcval").parent().next().children('select').val('03');//默认口服
            $("#" + rowid + "_pcCode").parent().next().children('select').html('').attr('disabled', 'true').css('background-color', '#f6f7fb');//禁用能量密度
        }
        
    }

    ///生成药品用法下拉框
    function Generatessypyfoption(rowid) {
        var curyfdm = $("#" + rowid + "_ypyfdm").val();
        var jxyf = top.top.clients.ypyf;//所有用法
        $("#" + rowid + "_yfmcval").parent().next().children('select').html('');
        if (top.clients.itemDetails) {
            var yfoption = "<option>请选择</option>";
            $.each(top.clients.itemDetails, function (idx, val) {
                if (val.Type === "CNYYYF") {
                    $.each(val.Items, function (key, val) {
                        if (curyfdm === val.Code) {
                            yfoption += '<option value="' + val.Code + '" selected>' + val.Name + '</option>';
                        } else {
                            yfoption += '<option value="' + val.Code + '">' + val.Name + '</option>';
                        }
                    });
                }
            });
            $("#" + rowid + "_yfmcval").parent().next().children('select').append(yfoption);
        }
    }

    function Generatenlmdoption(rowid) {
        var currentnlmd = $("#" + rowid + "_nlmddm").val();
        $("#" + rowid + "_pcCode").parent().next().children('select').html('');
        if (top.clients.itemDetails) {
            $.each(top.clients.itemDetails, function (idx, val) {
                if (val.Type === "NLMD") {
                    $.each(val.Items, function (key, value) {
                        if (value.Code == currentnlmd) {
                            $("#" + rowid + "_pcCode").parent().next().children('select').append('<option value="' + value.Code + '" selected>' + value.Name + '</option>');
                        } else {
                            $("#" + rowid + "_pcCode").parent().next().children('select').append('<option value="' + value.Code + '">' + value.Name + '</option>');

                        }
                         });
                }
            });
        }
    }
</script>


